package com.zhku.user.controller;

import com.zhku.base.model.PageParams;
import com.zhku.base.model.PageResult;
import com.zhku.base.model.RestResponse;
import com.zhku.user.model.dto.AddressDto;
import com.zhku.user.model.dto.ReturnShoppingCartDto;
import com.zhku.user.model.dto.ShoppingCartByNumDto;
import com.zhku.user.model.dto.ShoppingCartDto;
import com.zhku.user.model.po.TtUserAddress;
import com.zhku.user.service.TtUserShoppingcartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(value = "用户购物车相关接口",tags = "用户购物车相关接口")
@RestController
public class TtUserShoppingCartController {
    @Autowired
    TtUserShoppingcartService ttUserShoppingcartService;

    @ApiOperation("购物车点击+按钮添加商品")
    @PostMapping("/createShoppingcart")
    public RestResponse<ReturnShoppingCartDto> createShoppingcart(@RequestBody(required = false) ShoppingCartDto shoppingCartDto){
        ReturnShoppingCartDto shoppingcart = ttUserShoppingcartService.createShoppingcart(shoppingCartDto);
        return RestResponse.success(shoppingcart);
    }

    @ApiOperation("购物车点击-中减少商品")
    @PostMapping("/deleteShoppingcart")
    public RestResponse<ReturnShoppingCartDto> deleteShoppingcart(@RequestBody(required = false) ShoppingCartDto shoppingCartDto){
        ReturnShoppingCartDto shoppingcart = ttUserShoppingcartService.deleteShoppingcart(shoppingCartDto);
        return RestResponse.success(shoppingcart);
    }

    @ApiOperation("分页查询用户购物车中有哪些商品")
    @PostMapping("/getShopingcartList/{id}")
    public PageResult<ReturnShoppingCartDto> getShopingcartList(@RequestBody(required = false)PageParams pageParams, @PathVariable("id") String id){
        PageResult<ReturnShoppingCartDto> list = ttUserShoppingcartService.getShopingcartList(pageParams,id);
        return list;
    }

    @ApiOperation("支付成功后，从购物车中删除对应商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String", paramType="query"),
            @ApiImplicitParam(name = "goodsId", value = "商品id", required = true, dataType = "String", paramType="query")
    })
    @PostMapping("/deleteSuccessGoods")
    public boolean deleteSuccessGoods(String userId,String goodsId){
        boolean flag = ttUserShoppingcartService.deleteSuccessGoods(userId,goodsId);
        return flag;
    }

    @ApiOperation("添加商品到购物车，指定了商品数量")
    @PostMapping("/insertShoppingcartByNum")
    public RestResponse<ReturnShoppingCartDto> insertShoppingcartByNum(@RequestBody ShoppingCartByNumDto shoppingCartByNumDto){
        ReturnShoppingCartDto returnShoppingCartDto = ttUserShoppingcartService.insertShoppingcartByNum(shoppingCartByNumDto);
        return RestResponse.success(returnShoppingCartDto);
    }

    @ApiOperation("删除购物车中某个商品")
    @PostMapping("/dropShoppingcart")
    public RestResponse dropShoppingcart(@RequestBody ShoppingCartDto shoppingCartDto){
        ttUserShoppingcartService.dropShoppingcart(shoppingCartDto);
        return RestResponse.success();
    }

}
